package com.jt.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jt.pojo.Item;
import com.jt.pojo.ItemDesc;
import com.jt.service.DubboItemService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/items")
public class ItemController {

    @Reference(check = false, timeout = 3000)
    private DubboItemService itemService;

    /**
     * 业务: 根据itemId查询商品信息(item/itemDesc)
     * url : http://www.jt.com/items/562379.html
     * 参数: 注意restful风格即可
     * 返回值: 页面逻辑名称  item.jsp
     */
    @RequestMapping("/{itemId}")
    public String findItem(@PathVariable Long itemId, Model model) {

        Item item = itemService.findById(itemId);
        ItemDesc itemDesc = itemService.findItemDescById(itemId);
        model.addAttribute("item", item);
        model.addAttribute("itemDesc", itemDesc);
        return "item";
    }

}
